Expressions / Operators
Operators in Smowcode are used to create mathematical expressions, equations and logic conditions to process numbers and strings.
Expressions can be used on-the-go anywhere in Smowcode. Assign it to any node property, if condition or loop conditions.
Expressions
Expressions are equations created using constant numbers, strings, arrays and variables.
Eg. "My name is " + name, a + b, "My new value is " + ( ( 555 + x ) / (100 - y) ), a // b, a[i] % 2 == 0.
An expression can contain both numbers and strings of type flow or global. In case the node property expects a number and not a string, only numbers (variables/constants) should be included in the expression.
Constant strings are expressed in double quotes in an expression.
Operators
Following is the list of allowed operators.
| Operator | Operation | Description |
|---|---|---|
| + | Addition / String concatenation | Add 2 numbers or merge 2 strings |
| - | Subtraction | Subtract right operand from left operand |
| * | Multiply | Multiple 2 numbers |
| / | Divide | Divides left operand with left operand but result an integer/float(decimal) |
| // | Divide | Divides left operand with left operand but result only an integer |
| % | Modulus | Divides left-hand operand by right-hand operand and results a remainder. |
| () | Brackets | Allows BODMAS |
| == | Equal to | Compare if 2 numbers if equal; results 0(false) / 1(true) |
| != | Not Equal to | Compare if 2 numbers are not equal; results 0(false) / 1(true) |
| > | Greater than | Check if the left operand is greater than the right operand; results 0(false) / 1(true) |
| < | Less than | Check if the left operand is lesser than the right operand; results 0(false) / 1(true) |
| >= | Less than or equal | Check if the left operand is greater than or equal to the right operand; results 0(false) / 1(true) |
| <= | Greater than or equal | Check if the left operand is lesser than or equal to the right operand; results 0(false) / 1(true) |
| && | AND (Logical) | If both of the two operands are non-zero, then the condition becomes true. |
| || | OR (Logical) | If any of the two operands are non-zero, then the condition becomes true. |
| & | AND (Bitwise) | Perform AND operation on each bit of the operands on its left and right. |
| | | OR (Bitwise) | Perform OR operation on each bit of the operands on its left and right. |
| ^ | XOR (Bitwise) | Perform XOR operation on each bit of the operands on its left and right. |
| << | Left Shift | The left operands value is moved left by the number of bits specified by the right operand. New bits on the right will be 0s. |
| >> | Right Shift | The left operands value is moved right by the number of bits specified by the right operand. New bits on the left will be 0s. |
We are yet to support the following operators:
++eg.i++.--eg.i--.?:eg.a ? 0 : 1!eg.!myCondition
:::